from spass.core.db.init_db_core import init_db_core
from spass.core.warehouse import core_w_create
from spass.core.message import message
from optparse import OptionParser
import os

def init(argv):
    ex = True
    v = True
    parser = OptionParser()
    parser.add_option("--example", action="store_true", dest="ex", help="example...")
    parser.add_option("--verbose", action="store_true", dest="v", help="verbose mode in the make of the database")
    
    (options, args) = parser.parse_args(argv)

    if options.ex == None:
        ex = False
    if options.v == None:
        v = False
        
    ret = init_db_core(example=ex, verbose=v)
    
    if ret == 1:
        return 1
    ret = core_w_create()
    if ret == 1:
	return 1

    file(os.getenv('SPASS_ROOT')+"/core/.initialized", "w")
    message("custom", ["Spass has been successfully initialized", ''])
    return 0
